#ifndef VDPROTOCOL_H
#define VDPROTOCOL_H

#include <QByteArray>
#include <QObject>

#include "VDEnums.h"

class VDUser;

class ShortInfo
{
public:
	QString ID_sender;
	quint16 checkSum;
	VD::UserState state;
};


class VDProtocol : public QObject
{
	Q_OBJECT

public:
	enum TYPE
	{
		MES_USER_INFO_SHORT = 1,// ID_sender, 
		MES_USER_INFO_FULL,
		MES_TAKE_INFO_FULL,

		MES_SEND_ONE,
		MES_SEND_MANY,
		MES_SEND_CHAT,
		MES_ANSWER,
	};

	enum{ TYPE_COUNT = MES_ANSWER + 1,};

public:
	VDProtocol(QObject *parent);
	~VDProtocol();
	QByteArray makePackage_MES_USER_INFO_SHORT(const VDUser &user);
	QByteArray makePackage_MES_USER_INFO_FULL(const VDUser &user);
	QByteArray makePackage_MES_TAKE_INFO_FULL(const VDUser &user, const QString &takeInfoID);

	QByteArray makePackage_MES_SEND_ONE(const VDUser &user, const QString &receiveID, const QString &text);
	QByteArray makePackage_MES_SEND_MANY(const VDUser &user, const QStringList &receiveIDs, const QString &text);

	QByteArray makePackage_MES_SEND_CHAT(const VDUser &user, const QString &text);

	QByteArray makePackage_MES_ANSWER(const VDUser &user, const QString &receiveID, quint16 checkSum);

	void readPackage(const QByteArray& data); 

protected:
	//	void (MessageParser::*lpf_readPackage)(const QByteArray& data) [TYPE_COUNT];

	void makeHeader(QDataStream& stream, quint8 type, const VDUser& user);

	void readPackage_MES_USER_INFO_SHORT(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_USER_INFO_FULL(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_TAKE_INFO_FULL(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_SEND_ONE(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_SEND_MANY(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_SEND_CHAT(QDataStream& stream, const ShortInfo &sender);
	void readPackage_MES_ANSWER(QDataStream& stream, const ShortInfo &sender);

signals:
	void signalError(const QString &str);

	void signal_MES_USER_INFO_SHORT(const ShortInfo &sender);
	void signal_MES_USER_INFO_FULL(const VDUser &user);
	void signal_MES_TAKE_INFO_FULL(const ShortInfo &sender, const QString &takeInfoID);

	void signal_MES_SEND_ONE(const ShortInfo &sender, 
		const QString &receiveID, const QString &text);

	void signal_MES_SEND_MANY(const ShortInfo &sender,
		const QStringList &receiveIDs, const QString &text);

	void signal_MES_SEND_CHAT(const ShortInfo &sender, 
		const QString &text);

	void signal_MES_ANSWER(const ShortInfo &sender,
		quint16 checkSumMes);
};

#endif // VDPROTOCOL_H
